package com.woyowodaows.dialog;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.woyowodaows.R;
import com.woyowodaows.activity.mine.VersionUpdateBean;


/**
 * @author haiwei
 * 版本更新
 *  2018/5/28
 */

public class VersionUpdateDialog {

    private Context context;
    public Dialog dialog;
    private TextView tv_app_info;
    private TextView tv_update_message;
    public TextView tv_update_cancel;
    private TextView tv_update_sure;

    public VersionUpdateDialog(Context context) {
        this.context = context;
        initDialog();
    }

    private void initDialog() {
        dialog = new Dialog(context, R.style.dialog);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(false);
        Window window = dialog.getWindow();
        window.setContentView(R.layout.dialog_version_update);
        tv_app_info = (TextView) window.findViewById(R.id.tv_app_info);
        tv_update_message = (TextView) window.findViewById(R.id.tv_update_message);
        tv_update_cancel = (TextView) window.findViewById(R.id.tv_update_cancel);
        tv_update_sure = (TextView) window.findViewById(R.id.tv_update_sure);

        tv_update_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismissDialog();
            }
        });
    }

    public void setData(VersionUpdateBean versionUpdateBean, View.OnClickListener onClickListener){
        tv_update_sure.setOnClickListener(onClickListener);
        if (!TextUtils.isEmpty(versionUpdateBean.getVersionName())) {
            tv_app_info.setText("最新版本："+versionUpdateBean.getVersionName());
        }
        if (!TextUtils.isEmpty(versionUpdateBean.getDepict())) {
            tv_update_message.setText(versionUpdateBean.getDepict());
        }
    }

    /**
     * 显示dialog
     */
    public void showDialog() {
        if (dialog != null)
            dialog.show();
    }

    /**
     * 关闭dialog
     */
    public void dismissDialog() {
        if (dialog != null)
            dialog.dismiss();
    }

}
